import customSvg from "../components/customSvg";
import { useTranslation } from "react-i18next";
const CNIcon = customSvg["CNIcon"];
const ENIcon = customSvg["ENIcon"];

import useLanguageStore from "../store/language";

export default function Language() {
  const lang = useLanguageStore((state) => state.curLanguage);
  const updateLanguage = useLanguageStore((state) => state.updateLanguage);
  const { i18n } = useTranslation();

  const handleClick = () => {
    if (lang.locale === "zh-cn") {
      updateLanguage("enGB");
      i18n.changeLanguage("en");
    } else {
      updateLanguage("zhCN");
      i18n.changeLanguage("zh-cn");
    }
  };

  return (
    <div
      className=" p-2 fixed left-6 bottom-6 rounded-full bg-turquoise flex items-center justify-center shadow-lg cursor-pointer"
      onClick={handleClick}
    >
      {lang.locale === "zh-cn" ? <CNIcon /> : <ENIcon />}
    </div>
  );
}
